//
//  BoardCell.m
//  hexa
//
//  Created by kelly on 2015. 1. 5..
//  Copyright (c) 2015년 campmobile. All rights reserved.
//

#import "BoardCell.h"

@implementation BoardCell

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        _blockType = BlockTypeNone;
    }
    return self;
}

- (void)drawRect:(CGRect)rect
{
    // Drawing code
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextClearRect(context, rect);
    
    UIColor *color = [UIColor whiteColor];
    
    if (_blockType == BlockTypeGreen) {
        color = [UIColor greenColor];
    } else if (_blockType == BlockTypeRed) {
        color = [UIColor redColor];
    } else if (_blockType == BlockTypeBlue) {
        color = [UIColor blueColor];
    } else if (_blockType == BlockTypePurple) {
        color = [UIColor purpleColor];
    } else if (_blockType == BlockTypeSkyBlue) {
        color = [UIColor brownColor];
    } else if (_blockType == BlockTypeYellow) {
        color = [UIColor yellowColor];
    } else if (_blockType == BlockTypeNone) {
        color = [UIColor whiteColor];
    }
    
    const size_t totalComponents = CGColorGetNumberOfComponents(color.CGColor);
    const CGFloat *components = CGColorGetComponents(color.CGColor);
    
    CGContextSetRGBFillColor(context, components[MIN(0, totalComponents - 2)], components[MIN(1, totalComponents - 2)], components[MIN(2, totalComponents - 2)], 1.0f);
    CGContextFillRect(context, rect);
}

@end
